<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>{BEESCRM:$title}</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/base/busbooking/css/style.css">
    <link rel="stylesheet" href="/assets/public/layermobile/css/layer.css">
</head>
<body>
<div class="wraper white-bg">
    <form id="imgform" method="post" enctype="multipart/form-data">
        <div class="header">
            <a href="javascript:history.go(-1)" class="iconfont icon-llmainpageback back "></a>

            <div class="title text-center font-16">公交专线订票</div>
        </div>

        <div class="upload">
            <div class=" photo-border relative_" id="portrait-wraper">
                <img class="clip-img" accept="image/*" src="/assets/base/busbooking/images/uploading.png" alt="">
                <input type="file" id="file" class="upload-img" name="upload-img" id="upload-img"/>
            </div>
            <p class="text-center gray2">上传头像</p>
        </div>

        <div class="photoClip" id="photoClip">
            <div class="header clearfix">
                <div class="flex-between">
                    <a href="/Base/Center/center/apply_id/{BEESCRM:$applyId}/account_id/{BEESCRM:$account_id}"
                       class="iconfont icon-llmainpageback "></a>
                    <div class="title text-center font-16">{BEESCRM:$title}</div>
                    <a href="#" class="pull-right text-right save" id="edit-btn">完成</a>
                </div>
            </div>

            <!--图片加载-->
            <div id="photoClip-wrapper">
                <div class="lazy_tip" id="lazy_tip"><span>1%</span><br> 载入中......</div>
                <div class="lazy_cover"></div>
                <div class="pic_edit">
                    <div id="clipArea"></div>
                </div>
                <img src="" fileName="" id="hit">
            </div>

        </div>
        <input type="hidden" value="{BEESCRM:$subscribe}" id="keep"/>
        <a href="#" class="btn text-center font-16" id="submit">提交</a>

        <p class="text-center gray font-12 margin-t10"><span class="red">注：</span>请上传真实头像，以免影响您的乘车检票！</p>
    </form>
    <div class="pop-box hide" id="subscribe">
        <div class="pop-attention">
            <div class="erweima_img">
                <img src="/assets/base/busbooking/images/gongzonghao.jpg" alt="">
            </div>
            <p class="text-center font-12">
                长按识别以上二维码，
            </p>
            <p class="text-center font-12 margin-t4">关注“浙中医大后勤”后可进行购票</p>
        </div>
    </div>
</div>
</body>
<script src="/assets/base/busbooking/js/public.js"></script>
<script src="/assets/base/busbooking/js/layer.js"></script>
<script src="/assets/base/busbooking/js/jquery-2.1.0.min.js"></script>
<script src="/assets/base/busbooking/js/mobiscroll.custom-3.0.0-beta2.min.js"></script>
<script src="/assets/base/userCenter/static/publicjs/iscroll-zoom.js"></script>
<script src="/assets/base/userCenter/static/publicjs/jquery.photoClip.js"></script>
<script>
    photoClipInterfaceInit(
        "#photoClip",
        "#edit-btn",
        "#head-ortrait",
        "#portrait-wraper");
    var subscribe=$('#keep').val();
    if(subscribe==0){
        $('#subscribe').removeClass('hide');
    }
    var height = $(window).height();
    $('.wraper').css('minHeight', height);

    $('.photo-border').click(function () {
        $(this).nextAll('.upload-img').click();
    });

    //    function showPreview(source) {
    //        var file = source.files[0];
    //        if (window.FileReader) {  //当浏览器支持fileReader
    //            var fr = new FileReader();
    //            fr.onloadend = function (e) {
    //                var img = document.createElement("img");
    //                img.onerror = null;
    //                img.src = e.target.result;
    //                img.alt = '';
    //                img.id = 'pic';
    //                //$("#portrait").attr('src', e.target.result);
    //                $('.clip-img').attr('src', e.target.result);
    //            };
    //            fr.readAsDataURL(file);
    //        }
    //    }

    $('#submit').click(function () {
        var src = $('.clip-img').attr("src");
        if (src == '/assets/base/busbooking/images/uploading.png') {
            fm.alert('请上传图片');
            return;
        }

        var data = {};
        //var form = new FormData(document.getElementById("imgform"));
        data.picture = $("#file").attr('value');
        //删除字符串前的提示信息 "data:image/png;base64,"
        data.picture = data.picture.substring(22);
        $.ajax({
            type: 'post',
            dataType: "json",
            data: data,
            url: '/Base/BusBooking/generatePicture/apply_id/{BEESCRM:$apply_id}',
            success: function (result) {
                if (result.status == 'S') {
                    fm.alert('上传成功');
                    window.location.href = "/Base/BusBooking/demand/apply_id/{BEESCRM:$apply_id}";
                } else {
                    fm.alert('上传失败');
                    reload();
                }
            }
        })
    });
    function reload() {
        setTimeout('location.reload()', 2000);
    }

</script>
</html>